// 数量录入表
<template>
  <div class="container">
    <cargo-input-content
      :operaList="operaList"
      :tableList="tableList"
      :tableData="tableData"
      :res="res"
      :kind="kind"
      :total_count="total_count"
      :collection="false"
      @getData="getData"
      @deleteData="deleteData"
      @addData="addData"
      @editData="editData"
    >
      <template slot="navBar">
        <el-select @change="selectChange(value)" v-model="value" filterable placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </template>
    </cargo-input-content>
  </div>
</template>

<script>
import { GetWeight } from '@/api/cargo.js'
import { Delete } from '@/api/reusable.js'
import '@/mock/default.js'
import { tableMix } from '@/mixin/tableMix.js'
import { weightOperaList as operaList } from '@/assets/staticData/operaList/cargo.js'
import { weightTableList as tableList } from '@/assets/staticData/tableList/cargo.js'
export default {
  name: '',
  components: {},
  props: {},
  mixins: [tableMix], // 一些公用的属性方法可以放在mixin里面,各个组件互不影响
  data () {
    return {
      options: [
        {
          value: 'Φ600',
          label: 'Φ600'
        },
        {
          value: 'Φ550',
          label: 'Φ550'
        },
        {
          value: 'Φ500',
          label: 'Φ500'
        },
        {
          value: 'Φ450',
          label: 'Φ450'
        },
        {
          value: 'Φ400',
          label: 'Φ400'
        },
        {
          value: 'Φ350',
          label: 'Φ350'
        },
        {
          value: 'Φ300',
          label: 'Φ300'
        },
        {
          value: 'Φ250',
          label: 'Φ250'
        },
        {
          value: 'Φ200',
          label: 'Φ200'
        },
        {
          value: 'Φ234',
          label: 'Φ234'
        },
        {
          value: 'Φ256',
          label: 'Φ256'
        },
        {
          value: 'Φ288',
          label: 'Φ288'
        },
        {
          value: 'Φ315',
          label: 'Φ315'
        },
        {
          value: 'Φ333',
          label: 'Φ333'
        },
        {
          value: '次品',
          label: '次品'
        }
      ],
      value: 'Φ600'
    }
  },
  computed: {},
  watch: {},
  beforeCreate () {},
  created () {
    if (sessionStorage.getItem('select')) {
      this.value = sessionStorage.getItem('select')
    }
    this.kind = this.value
    this.getData({
      diameter: this.kind,
      page: 1,
      per_page: 10,
      time_stamp1: new Date().getTime() - 3000 * 1000 * 24 * 3,
      time_stamp2: new Date().getTime()
    })
  },
  mounted () {},
  methods: {
    addData (data) {
      this.$axios.get('http://127.0.0.1:7002/addRes')
        .then(res => {
          this.res = res.data
        })
    },
    editData (_id, data) {
      this.$axios.get('http://127.0.0.1:7002/editRes')
        .then(res => {
          // console.log(res)
          this.res = res.data
        })
    },
    getData (data) {
      this.operaList = operaList
      this.tableList = tableList
      // console.log('获取', data)
      GetWeight(data).then(res => {
        console.log('getData res', res)
        if (res.data.data.results === null) {
          this.tableData = []
        } else {
          this.tableData = res.data.data.results
        }
        this.total_count = res.data.data.total_count
      })
    },
    deleteData (data) {
      console.log('我是父组件，我来接收数据', data)
      // this.$axios.get('http://127.0.0.1:7002/delRes')
      Delete({
        _id: data._id,
        collection: 'weight'
      })
        .then(res => {
          console.log(res)
          this.res = res
          this.getData({
            page: 1,
            per_page: 10
          })
        })
    },
    selectChange (i) {
      // console.log(i)
      this.kind = i
      this.getData({
        diameter: this.kind,
        page: 1,
        per_page: 10,
        time_stamp1: new Date().getTime() - 3000 * 1000 * 24 * 3,
        time_stamp2: new Date().getTime()
      })
      sessionStorage.setItem('select', i)
    }
  }
}
</script>

<style scoped lang="">
</style>
